<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="app">
    <p>总数：{{total}}</p>
    <my-component v-model="total"></my-component>
    <my-component @input="handleTotal"></my-component>
</div>
<script>
    Vue.component('my-component', {
        template:'<div><button @click="handleClick">+1</button></div>',
        data() {
            return{
                counter:0
            }
        },
        methods:{
            handleClick() {
                this.counter++
                this.$emit('input', this.counter)
            }
        }
    })
    var vm=new Vue({
        el:'#app',
        data:{
            total:0
        },
        methods:{
            handleTotal(total){
                this.total=total
            }
        }
    })
</script>
</body>
</html>
